Skip to content

Conversation

will-v-pi
Copy link
Contributor

@will-v-pi will-v-pi commented Dec 13, 2024

This adds a function to create binaries with modified RAM/SCRATCH addresses

For example, to only use SRAM1 so you can power down SRAM0 in your binary you could use

pico_set_modified_binary_type(<my_exe> flash RAM "0x20040000" "256k")

To create a XIP_SRAM only binary you could use

pico_set_modified_binary_type(<my_exe> sram
    RAM "0x13ffc000" "12k"
    SCRATCH_X "0x13fff000" "2k"
    SCRATCH_Y "0x13fff800" "2k")

The existing memmap_blocked_ram.ld could be created using

pico_set_modified_binary_type(<my_exe> flash RAM "0x21000000" "256k")

This adds some tests to kitchen_sink to ensure that these generated linker scripts match the default ones, to prevent them diverging

@kilograham kilograham self-assigned this Jan 11, 2025
@kilograham kilograham self-requested a review January 11, 2025 19:59
@kilograham
Copy link
Contributor

kilograham commented Jan 11, 2025

this is useful functionality; we need to think about whether this is best as modifying the linker script or injecting as per FLASH_SIZE (either way it should - and i think it is for FLASH_SIZE be modifiable via linker script)

@kilograham kilograham added this to the 2.2.0 milestone Jan 31, 2025
@lurch lurch added the build label Mar 20, 2025
@lurch
Copy link
Contributor

lurch commented Mar 20, 2025

To create a XIP_SRAM only binary you could use

pico_set_modified_binary_type(<my_exe> no_flash
    RAM "0x13ffc000" "12k"
    SCRATCH_X "0x13fff000" "2k"
    SCRATCH_Y "0x13fff800" "2k")

Perhaps it would be nice if you could use symbolic aliases here, rather than having to use hardcoded addresses? 🤷

@lurch
Copy link
Contributor

lurch commented Mar 20, 2025

Maybe this is a first step towards #1547 ?

Allows creating binaries using an existing binary type & linker script, but with modified RAM/SCRATCH addresses

For example, to only use SRAM1 so you can power down SRAM0 in your binary you could use `pico_set_modified_binary_type(<my_exe> no_flash RAM "0x20040000" "256k"`
New template flash and sram linker scripts, to avoid need for parsing the file

Adds a test to kitchen_sink that these new linker scripts produce the same defaults, to ensure modifications to linker scripts are propogated
@will-v-pi will-v-pi force-pushed the set-modified-binary-type branch from 664d230 to 4430502 Compare September 1, 2025 13:53
@will-v-pi
Copy link
Contributor Author

this is useful functionality; we need to think about whether this is best as modifying the linker script or injecting as per FLASH_SIZE (either way it should - and i think it is for FLASH_SIZE be modifiable via linker script)

I've thought it through a bit more - injecting like FLASH_SIZE wouldn't work, because you might need different injected bits for each binary in your project, whereas FLASH_SIZE is set project-wide as it's fixed for a given board

Instead, I've added separate template linker scripts memmap_sram.template.ld and memmap_flash.template.ld, which are copies of memmap_no_flash.ld and memmap_default.ld respectively with the RAM and SCRATCH regions set to be templated. I've also added tests at compile time to kitchen_sink to ensure these files stay in sync.

These template linker scripts could then be extended further to support #1547 - but I think that's probably best for a second PR, I'd like to just get this functionality in first so you can make SRAM1 or XIP_SRAM binaries

@@ -0,0 +1,286 @@
/* Based on GCC ARM embedded samples.
Defines the following symbols for use by code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a load of double-underscore identifiers (e.g. __logical_binary_start, __embedded_block_end, __binary_info_start) which aren't included in this list. Should they be? 🤷 (I know almost nothing about linker scripts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an identical copy of memmap_default.ld, so changing anything other than the memory regions is outside the scope of this PR - maybe worth pinging @kilograham about tidying up the linker scripts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants